Optimize SourceId::cmp a bit
authorAlex Crichton <alex@alexcrichton.com>
Sat, 30 May 2015 02:25:19 +0000 (19:25 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 3 Jun 2015 01:05:47 +0000 (18:05 -0700)
src/cargo/core/source.rs

index 8a89c55466d3d5f74fcc3d4ff75924069596ec4a..7551161bc62cb73954d7fc4c13cbbfa2ae5024e4 100644 (file)
@@ -245,13 +245,23 @@ impl PartialEq for SourceId {
 
 impl PartialOrd for SourceId {
     fn partial_cmp(&self, other: &SourceId) -> Option<Ordering> {
-        self.to_string().partial_cmp(&other.to_string())
+        Some(self.cmp(other))
     }
 }
 
 impl Ord for SourceId {
     fn cmp(&self, other: &SourceId) -> Ordering {
-        self.to_string().cmp(&other.to_string())
+        match self.inner.kind.cmp(&other.inner.kind) {
+            Ordering::Equal => {}
+            ord => return ord,
+        }
+        if let Kind::Git(..) = self.inner.kind {
+            match self.inner.precise.cmp(&other.inner.precise) {
+                Ordering::Equal => {}
+                ord => return ord,
+            }
+        }
+        self.inner.url.to_string().cmp(&other.inner.url.to_string())
     }
 }